<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="author" content="zhupeng">
<TITLE>订单管理</TITLE>
<script type="text/javascript" language="javascript" src="../script/common.js"></script>
<script type="text/javascript" language="javascript">
			//全局变量
			var org = Common.cOrg();	//当前单位	
			var qt = {};				//数据表格对象
			var cnt = {};
			var qt2 = {};				//数据表格对象2
			//页面加载方法
			function load(){ 
				Eui.showNavigation();
				searchForm.location.value = org.id;
				Eui.initBeginDateInput("beginDateTd","起始日期","searchForm","beginDate","endDate","_pastDate");
				Eui.initEndDateInput("endDateTd","结束日期","searchForm","beginDate","endDate","_pastDate");
			
				//var card_status = Common.getSubsetItems(CardStatus.CATEGORY, [CardStatus.INITED, CardStatus.OK]);
				
				Common.initDict("orderStatus","orderStatus","全部");
				Common.initDict("factoryBillStatus","factoryBillStatus","全部");
				
				setPages(["listview","amply","detview","fileView","editdiv"]);	
				
				createTable();	
			} 
			 
			//生成表格，创建QueryTable对象(查询)
			function createTable(){
				var columns = [];
				columns[20]= {title:"操作",width:"15%",render:operationFunc,order:false};													
				qt = new QueryTable("suborder_manager_query","searchForm","datalist",columns,{
					displayColumns: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,20],
					buttons:[
						{value:"增加",actions:onNew}
					]
				});
			}
			
		function onNew(){
			Rpc.loadPage("editdiv","/aita/subOrderView.html")
			
			Common.initDict(diamondform.colorType,"colorType","全部");
			Common.initDict(diamondform.neatness,"neatness","全部");
			Common.initDict(diamondform.certificateType,"certificateType","全部");
			Common.initDict(diamondform.cut,"cut","全部");
			Common.initDict(diamondform.shape,"shape","全部");
			Common.initDict(diamondform.shape,"shape","全部");
			Common.initDict(diamondform.heartAndArrow,"heartAndArrow","全部");
			
			Common.initDict(factorybillform.isReturn,"isReturn","全部");
			Common.initDict(factorybillform.isArrive,"isArrive","全部");
			Common.initDict(factorybillform.factory,"factory","全部");
			
			
			switchPage('editdiv');
		}
			
		function importFile(){
			fileForm.reset();//todo
			switchPage("fileView");
		}

		function operationFunc(v,r){
			return "<div style='color:gray'><a href=# onclick=onEidt('"+r[0]+"')>查看</a>  <a href=# onclick=onCommit('"+r[0]+"')>提交</a>   <a href=# onclick=onfinishOrder('"+r[0]+"')>取货</a>";
		}
			
		
	function onEidt(id){
		onNew()
		$("saveBut").onclick=onSave;
		DWR.call("orderService.loadOrder",id,function(data){
			var order = data.order;
			var customer = data.customer;
			var diamond = data.diamond;
			var factorybill = data.factoryBill;
			
			diamond.weight = Format.fenToYuan(diamond.weight);
			
			Common.setValues(cardtypeform,order);
			Common.setValues(diamondform,diamond);
			Common.setValues(customerform,customer);
			Common.setValues(factorybillform,factorybill);
			var org = data.org;
			diamondform.orgName.value = org.name;
		});
	}
	
	
		function onCommit(id){
		DWR.call("orderService.commitOrder",id,function(data){
				showInformation("提交成功!");	
				showData();
		},{blockScreen:"true"});
	}
	
	
	function onfinishOrder(id){
		DWR.call("orderService.finishOrder",id,function(data){
				showInformation("取货完成!");	
				showData();
		},{blockScreen:"true"});
	}
	
	function onSave(){
		if(!checkForm("cardtypeform"))return;
		if(!checkForm("customerform"))return;
		if(!checkForm("diamondform"))return;
		
		var factoryBill = Common.getValues(factorybillform);
		var customer = Common.getValues(customerform);
		var order = Common.getValues(cardtypeform);
		var diamond = Common.getValues(diamondform);
		
		diamond.weight = Format.yuanToFen(diamond.weight);
		DWR.call("orderService.saveOrder",order,customer,diamond,factoryBill,function(result){
			showInformation("保存成功!");	
			onBack1();
		},{blockScreen:"true"});
		
		
	}
	
	
			
	//选择钻石
	function onBack(){
		openDialogFrame("/aita/diamond.html","选择钻石",800,1000,function(v){
			if (!v) return;
			
			DWR.call("diamondService.loadDiamond",v.id,function(data){
			var diamond = data.diamond;
			var org = data.org;
			
			diamond.weight = Format.fenToYuan(diamond.weight);
			diamond.amount = diamond.amount * parseInt(org.description)/100;
			
			Common.setValues(diamondform, diamond);
			diamondform.orgName.value = org.name;
		});
		})
	}
	
	function onBack1(){
		switchPage('listview');
		showData();
	}
	

	function showData(){
		searchForm.org.value = org.id;
	  	qt.showTable();
	}
	
		//选择操作员
        function selOper() {
			SystemMgnt.selOperator(function(v) {
				if (!v) return;
				searchForm.operatorName.value = v.name;
				searchForm.oper.value = v.id;
			}, {orgId:org.id})
		}
	
	</script>
</head>
<body onload="load()">
<!--页面导航-->
<div class="nav">
<div id="nav">&nbsp;</div>
</div>
<!--查询静态页面部分-->
<div id="listview"><!--查询条件form-->
<div class="searchForm">
<form id="searchForm" name="searchForm">
<input type="hidden" id="location" name="location">
<input type="hidden" id="oper" name="oper">
<input type="hidden" id="org" name="org">
<table cellSpacing=0 cellPadding=4 width="100%" border=0>

	<tr>
		<td id="beginDateTd"></td>
		<td class="Label4"><label>销售人员</label> <input type="text" name="operatorName">
							<a class=orga href=# onclick="selOper();">&nbsp;&nbsp;</a></td>
		<td><label>客户姓名</label> <input type="text" name="customer"
			onblur="" maxlength=24></td>
		
	</tr>
	<tr>
		<td id="endDateTd"></td>
		<td><label>订单状态</label> <select name="orderStatus"></select></td>
		<td><label>加工单状态</label> <select name="factoryBillStatus"></select></td>
		<td><button type="button" onclick="showData()">查 询</button>
		</td>
	</tr>
</table>
</form>
</div>
<div id="datalist"></div>
</div>

<div id=editdiv style="display:none;"></div>
</body>
</HTML>